﻿using System;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace SoftwareEngineering_Project
{
    public partial class Login : System.Web.UI.Page
    {
        private SoftwareEngineering_Project.User CurrentUser
        {
            get
            {
                return (SoftwareEngineering_Project.User)Session["CurrentUser"];
            }
            set
            {
                Session["CurrentUser"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            User user = new User();
            if (user.CheckifuserExists(UserName.Text, Password.Text))
            {
                if (user.Checkifuserregistered(UserName.Text))
                {
                    user.getUser(UserName.Text);
                    CurrentUser = user;
                    Response.Redirect("~/default.aspx");
                }
                else
                {
                    Errormessage.Visible = true;
                    Errormessage.Text = "User name and Password are correct but you need to confirm your registration by following the instructions on the email";
                }
            }
            else
            {
                Errormessage.Visible = true;
                Errormessage.Text = "User name or password is incorrect!";
            }
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        
    }
}